package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.Textbook;
import com.ruoyi.manage.service.ITextbookService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教材列表Controller
 * 
 * @author rjgc17
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/manage/textbook")
public class TextbookController extends BaseController
{
    @Autowired
    private ITextbookService textbookService;

    /**
     * 查询教材列表列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:list')")
    @GetMapping("/list")
    public TableDataInfo list(Textbook textbook)
    {
        startPage();
        List<Textbook> list = textbookService.selectTextbookList(textbook);
        return getDataTable(list);
    }

    /**
     * 导出教材列表列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:export')")
    @Log(title = "教材列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Textbook textbook)
    {
        List<Textbook> list = textbookService.selectTextbookList(textbook);
        ExcelUtil<Textbook> util = new ExcelUtil<Textbook>(Textbook.class);
        util.exportExcel(response, list, "教材列表数据");
    }

    /**
     * 获取教材列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(textbookService.selectTextbookById(id));
    }

    /**
     * 新增教材列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:add')")
    @Log(title = "教材列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Textbook textbook)
    {
        return toAjax(textbookService.insertTextbook(textbook));
    }

    /**
     * 修改教材列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:edit')")
    @Log(title = "教材列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Textbook textbook)
    {
        return toAjax(textbookService.updateTextbook(textbook));
    }

    /**
     * 删除教材列表
     */
    @PreAuthorize("@ss.hasPermi('manage:textbook:remove')")
    @Log(title = "教材列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(textbookService.deleteTextbookByIds(ids));
    }
}
